// ===================================
// <copyright>
// This file is part of LABSMFController.
//
//    LABSMFController is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    LABSMFController is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with LABSMFController.  If not, see <http://www.gnu.org/licenses/>.
//    Copyright 2011 David Bakker
//
//</copyright>
// <author>David Bakker</author>
// <email>mailto:DavidFBakker@gmail.com</email>
// <created>Saturday, May 07, 2011</created>
// <lastedit>Saturday, May 07, 2011</lastedit>
// ===================================

using System;
using BakkerBeer;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;

namespace LABSMFControllerMFCobra.Modules
{

    public class TempModule : Modules
    {
        private static readonly Font TempFont = Resources.GetFont(Resources.FontResources.small);
        private bool _isHighTriggerSet;
        private bool _isLowTriggerSet;

        private DispatcherTimer _update;

        public TempModule()
        {
            _isHighTriggerSet = false;
            _isLowTriggerSet = false;
         
            LowTriggerSet = 0;
            HighTriggerSet = 0;
            Width = 125;
            Height = 125;
            Visibility = Visibility.Visible;
        }

        public TempModule(double hightTigger)
        {
            _isHighTriggerSet = true;
            _isLowTriggerSet = false;
         

            LowTriggerSet = 0;
            HighTriggerSet = hightTigger;
            Width = 125;
            Height = 125;
            Visibility = Visibility.Visible;
        }

        public TempModule(double hightTigger, double lowTrigger)
        {
            _isHighTriggerSet = true;
            _isLowTriggerSet = true;
         

            LowTriggerSet = lowTrigger;
            HighTriggerSet = hightTigger;
            Width = 125;
            Height = 125;
            Visibility = Visibility.Visible;
        }

        public double LowTriggerSet { get; set; }
        public double HighTriggerSet { get; set; }

        public override void Configure()
        {
            _update = new DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 0, 200)};
            _update.Tick += UpdateTick;
            _update.Start();
        }


        public override event HighTriggerHandler HighTrigger;

        public void InvokeHighTrigger(TriggerMessage triggerMessage)
        {
            HighTriggerHandler handler = HighTrigger;
            if (handler != null) handler(this, triggerMessage);
        }

        public override event LowTriggerHandler LowTrigger;

        public void InvokeLowTrigger(TriggerMessage triggerMessage)
        {
            LowTriggerHandler handler = LowTrigger;
            if (handler != null) handler(this, triggerMessage);
        }

        public override event StopTriggerHandler StopTrigger;
        public void InvokeStopTrigger(TriggerMessage triggerMessage)
        {
            StopTriggerHandler handler = StopTrigger;
            if (handler != null) handler(this, triggerMessage);
        }

        private void UpdateTick(object sender, EventArgs e)
        {
            Invalidate();
        }

        public override void OnRender(DrawingContext dc)
        {
            const int xTempOffset = 60;
            int y = 8;
            const int yOffset = 10;

            dc.DrawRectangle(new SolidColorBrush(Colors.White),
                             null,
                             0,
                             0,
                             Width,
                             Height
                );

           
        }
    }
}